﻿///----------------------------------------------------------------
/// Copyright (C) 2008-2010 yyssoft
/// 版权所有。
///
/// 文件名：YQCJDDAL.cs
/// 文件功能描述：YQCJD数据访问类
///
///
/// 创建标识：yyssoft 2014/5/19
///
/// 修改标识：
/// 修改描述：
///
/// 修改标识：
/// 修改描述：
///---------------------------------------------------------------
using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using XMK.Tadong.Model;
using XMK.Framework.DataAccess;
using System.Data.OleDb;

namespace XMK.Tadong.DAL
{
    /// <summary>
    /// YQCJD的数据访问类
    /// </summary>
    public class YQCJDDAL
    {

        #region  构造函数

        protected DbProvider dbProvider;
        public YQCJDDAL(DbProvider dbProvider)
        {
             this.dbProvider = dbProvider;
        }

        #endregion  构造函数

        #region  成员方法

        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>成功返回主标识ID,失败返回"0"</returns>
        public string AddBySql(YQCJDInfo model)
        {
//            StringBuilder sbSql = new StringBuilder(BEGINWITHOUTTRANSACTION);
//            sbSql.Append(@" INSERT INTO YQCJD 
//					([ID],[JH],[DJSD1],[DJSD2],[YCZMC],[HD]) 
//					VALUES(@ID,@JH,@DJSD1,@DJSD2,@YCZMC,@HD)");
//            sbSql.Append(ENDWITHOUTTRANSACTION);

//            OracleParameter[] parameters = {
//                    new OracleParameter(":"+YQCJDInfo.ID_FIELD, OracleType.Number,4),
//                    new OracleParameter(":"+YQCJDInfo.JH_FIELD, OracleType.VarChar,50),
//                    new OracleParameter(":"+YQCJDInfo.DJSD1_FIELD, OracleType.VarChar,50),
//                    new OracleParameter(":"+YQCJDInfo.DJSD2_FIELD, OracleType.VarChar,50),
//                    new OracleParameter(":"+YQCJDInfo.YCZMC_FIELD, OracleType.VarChar,50),
//                    new OracleParameter(":"+YQCJDInfo.HD_FIELD, OracleType.Number,4)};
//            parameters[0].Value = model.ID;
//            parameters[1].Value = model.JH;
//            parameters[2].Value = model.DJSD1;
//            parameters[3].Value = model.DJSD2;
//            parameters[4].Value = model.YCZMC;
//            parameters[5].Value = model.HD == int.MinValue ? DBNull.Value : (object)model.HD;  

//            return SqlHelper.ExecuteScalar(SqlHelper.LocalTransactionConnectionString, CommandType.Text, sbSql.ToString(), parameters).ToString();

            return "";
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>成功返回"1",失败返回"0"</returns>
        public string UpdateBySql(YQCJDInfo model)
        {
//            StringBuilder sbSql = new StringBuilder(BEGINWITHOUTTRANSACTION);
//            sbSql.Append(@" UPDATE YQCJD 
//					SET [JH] = @JH,[DJSD1] = @DJSD1,[DJSD2] = @DJSD2,[YCZMC] = @YCZMC,[HD] = @HD 
//					WHERE ID=:ID ");
//            sbSql.Append(ENDWITHOUTTRANSACTION);

//            OracleParameter[] parameters = {
//                    new OracleParameter(":"+YQCJDInfo.ID_FIELD, OracleType.Number,4),
//                    new OracleParameter(":"+YQCJDInfo.JH_FIELD, OracleType.VarChar,50),
//                    new OracleParameter(":"+YQCJDInfo.DJSD1_FIELD, OracleType.VarChar,50),
//                    new OracleParameter(":"+YQCJDInfo.DJSD2_FIELD, OracleType.VarChar,50),
//                    new OracleParameter(":"+YQCJDInfo.YCZMC_FIELD, OracleType.VarChar,50),
//                    new OracleParameter(":"+YQCJDInfo.HD_FIELD, OracleType.Number,4)};
//            parameters[0].Value = model.ID;
//            parameters[1].Value = model.JH;
//            parameters[2].Value = model.DJSD1;
//            parameters[3].Value = model.DJSD2;
//            parameters[4].Value = model.YCZMC;
//            parameters[5].Value = model.HD == int.MinValue ? DBNull.Value : (object)model.HD;

//            return SqlHelper.ExecuteScalar(SqlHelper.LocalTransactionConnectionString, CommandType.Text, sbSql.ToString(), parameters).ToString();
            return "";
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>成功返回"1",失败返回"0"</returns>
        public string DeleteBySql(int ID)
        {
//            StringBuilder sbSql = new StringBuilder(BEGINWITHOUTTRANSACTION);
//            sbSql.Append(@" DELETE YQCJD 
//					WHERE ID=:ID ");
//            sbSql.Append(ENDWITHOUTTRANSACTION);

//            OracleParameter[] parameters = {
//                    new OracleParameter(":ID", OracleType.Number,4)};
//            parameters[0].Value = ID;

//            return SqlHelper.ExecuteScalar(SqlHelper.LocalTransactionConnectionString, CommandType.Text, sbSql.ToString(), parameters).ToString();
            return "";
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DataTable GetModelBySql(int ID)
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append(@"SELECT ID,JH,DJSD1,DJSD2,YCZMC,HD 
					FROM YQCJD 
					WHERE ID=" + ID + " ");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, sbSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }

        //通过筛选条件获取数据
        public DataSet GetDataByWhere(string strWhere)
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append(@"SELECT ID,JH,DJSD1,DJSD2,YCZMC,HD FROM YQCJD  where 1=1 " + strWhere);
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, sbSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataSet ds = DbHelper.ExecFullDataSet(cmd.DbProvider, cmd.DbCmdInfo);

            return ds;
        }

        /// <summary>
        /// 根据JH列表在数据库中查询有那些井有录井图的数据，返回有数据的JH列表
        /// </summary>
        /// <param name="p_strJH">JH列表，型如：敖1,敖2,古23</param>
        /// <returns>JH列表，型如：敖1,敖2</returns>
        public DataSet GetHaveDataJH(string stringjh)
        {
            
            string strSQL = "select distinct(JH)   from YQCJD where JH in (" + stringjh + ")";
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSQL.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataSet ds = DbHelper.ExecFullDataSet(cmd.DbProvider, cmd.DbCmdInfo);

            return ds;
        }

        /// <summary>
        /// 通用查询
        /// </summary>
        /// <param name="SQL">传入的sql语句</param>
        /// <returns>datatable</returns>
        public DataTable QueryData(string SQL)
        {
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, SQL.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }

        /// <summary>
        /// 通用查询
        /// </summary>
        /// <param name="SQL">传入的sql语句</param>
        /// <returns>datatable</returns>
        public DataSet QueryDataReturnDataSet(string SQL)
        {
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, SQL.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataSet ds = DbHelper.ExecFullDataSet(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }

        /// <summary>
        /// 通用插入等操作
        /// </summary>
        /// <param name="SQL"></param>
        /// <returns></returns>
        public bool inserData(string SQL)
        {
            bool Flag=false;
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, SQL.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;

            if (DbHelper.ExecNonQuery(cmd.DbProvider, cmd.DbCmdInfo) > 0)
            {
                Flag = true;
            }
            return Flag;
                 
        }

             

        #endregion  成员方法

    }
}

